<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">
      <el-form-item label="姓名" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      
      <el-form-item label="导入时间" prop="importTime">
        <el-date-picker
          v-model="queryParams.importTime"
          size="small"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">查询</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
        >删除</el-button>
        <el-button
          type="primary"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
        >导出</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
    </el-row>

    <el-table v-loading="loading" :data="leadsList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="新导入线索" :span="4" align="center">
        <el-table-column label="姓名" align="center" prop="name" />
        <el-table-column label="手机号" align="center" prop="phone" />
        <el-table-column label="地址" align="center" prop="address" />
        <el-table-column label="导入时间" align="center" prop="importTime" width="180">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.importTime, '{y}-{m}-{d}') }}</span>
          </template>
        </el-table-column>
      </el-table-column>
      <el-table-column label="系统内重复线索" :span="4" align="center">
        <el-table-column label="姓名" align="center" prop="duplicateName" />
        <el-table-column label="手机号" align="center" prop="duplicatePhone" />
        <el-table-column label="地址" align="center" prop="duplicateAddress" />
        <el-table-column label="导入时间" align="center" prop="duplicateImportTime" width="180">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.duplicateImportTime, '{y}-{m}-{d}') }}</span>
          </template>
        </el-table-column>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { parseTime } from "@/utils/ruoyi";

export default {
  name: "LeadsRepeat",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      // 重复线索表格数据
      leadsList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: undefined,
        importTime: []
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询重复线索列表 */
    getList() {
      this.loading = true;
      // 使用mock数据
      this.leadsList = this.getMockData();
      this.total = this.leadsList.length;
      this.loading = false;
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 多选框选中数据 */
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!=1
      this.multiple = !selection.length
    },
    /** 删除按钮操作 */
    handleDelete() {
      const ids = this.ids;
      this.$confirm('是否确认删除选中的重复线索数据项？', '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        // 这里应该调用删除API，目前使用mock
        this.$message.success(`已删除 ${ids.length} 条重复线索`);
        this.getList(); // 重新加载数据
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      // 这里应该调用导出API，目前使用mock
      this.$message.info('导出功能待开发');
    },
    /** 时间格式化 */
    parseTime(time, format) {
      return parseTime(time, format);
    },
    /** 获取mock数据 */
    getMockData() {
      return [
        {
          id: 1,
          name: "张三",
          phone: "13800138000",
          address: "北京市朝阳区",
          importTime: "2025-10-20",
          duplicateName: "张三",
          duplicatePhone: "13800138000",
          duplicateAddress: "北京市朝阳区",
          duplicateImportTime: "2025-10-15"
        },
        {
          id: 2,
          name: "李四",
          phone: "13900139000",
          address: "上海市浦东新区",
          importTime: "2025-10-21",
          duplicateName: "李四",
          duplicatePhone: "13900139000",
          duplicateAddress: "上海市浦东新区",
          duplicateImportTime: "2025-10-18"
        },
        {
          id: 3,
          name: "王五",
          phone: "13700137000",
          address: "广州市天河区",
          importTime: "2025-10-22",
          duplicateName: "王五",
          duplicatePhone: "13700137000",
          duplicateAddress: "广州市天河区",
          duplicateImportTime: "2025-10-10"
        },
        {
          id: 4,
          name: "赵六",
          phone: "13600136000",
          address: "深圳市南山区",
          importTime: "2025-10-23",
          duplicateName: "赵六",
          duplicatePhone: "13600136000",
          duplicateAddress: "深圳市南山区",
          duplicateImportTime: "2025-10-12"
        },
        {
          id: 5,
          name: "钱七",
          phone: "13500135000",
          address: "杭州市西湖区",
          importTime: "2025-10-24",
          duplicateName: "钱七",
          duplicatePhone: "13500135000",
          duplicateAddress: "杭州市西湖区",
          duplicateImportTime: "2025-10-16"
        }
      ];
    }
  }
};
</script>